<template>
  <div class="my-questions">
    <white-header
      :isShowTopNav="true"
      :isShowBack="true"
      :isShowRight="true"
      :title="title"
    ></white-header>
    <div class="questions-list">
      <div
        class="question-box"
        v-for="(item, index) in questionList"
        :key="index"
        @click="handleJump(item)"
      >
        <div class="box-left">
          <img
            v-lazy="
              item.cover
                ? item.cover
                : '/img/mobile/question_menus_subject_new.png'
            "
            :key="item.cover"
          />
          <van-tag color="rgb(153 155 158)" class="delete_tag" v-if="item.isDelete == 1">已过期</van-tag>
        </div>
        <div class="box-right">
          <div class="question-name">
            {{ item.questionGroupName || "未知" }}
          </div>
          <div class="question-time">
            有效期:{{ trimDate(item.startTime) }}-{{ trimDate(item.endTime) }}
          </div>
          <div class="question-progress">
            <van-progress
              :percentage="item.percentage"
              stroke-width="8"
              color="var(--theme-color)"
              :show-pivot="false"
            />
          </div>
          <div class="question-info">
            <span style="color: var(--theme-color);"
              >总{{ item.totalNum || 0 }}道题</span
            >
            <span style="color: #949699;">已完成{{ item.doneNum || 0 }}道</span>
            <!-- <span style="color: #949699;">还未开始做题</span> -->
            <!-- <span style="color: #949699;">已完成所有题</span> -->
          </div>
        </div>
      </div>
      <van-empty
        v-if="questionList && questionList.length == 0"
        :description="'暂时没有题库哦~'"
      />
    </div>
  </div>
</template>

<script>
import { mapState, mapActions, mapMutations } from "vuex";
import WhiteHeader from "~/components/mobile/WhiteHeader.vue";
export default {
  scrollToTop: true,
  components: {
    WhiteHeader
  },
  data() {
    return {
      title: "我的题库"
    };
  },
  computed: {
    ...mapState({
      user_info(state) {
        return state.user_info;
      },
      token(state) {
        return state.token;
      },
      is_loading(state) {
        return state.is_loading;
      },
      shallowColor(state) {
        return state.web_info.THEME_COLOR + "32";
      },
      chartColor(state) {
        return state.web_info.THEME_COLOR;
      },
      questionList(state) {
        return state.questionBank.question_record_list.map(item=>{
          return {
            ...item,
            percentage:item.totalNum == 0 || item.doneNum == 0 ? 0 : parseInt((item.doneNum / item.totalNum) * 100)
          }
        });
      }
    })
  },
  watch: {},
  methods: {
    trimDate(date) {
      if (date) {
        let _date = new Date(date);
        return `${_date.getFullYear()}.${_date.getMonth() +
          1}.${_date.getDate()}`;
      } else {
        return this.$t("locale.components.mobile.GroupChat.t7");
      }
    },
    handleJump(item) {
      this.$router.push({ path: "/m/v2-question-detail?id=" + item.id });
    }
  },
  created() {
    
  },
  activated(){
    if (Object.keys(this.user_info).length == 0 || !this.token) {
      this.$router.push({
        path: "/m/login"
      });
    }
  },
  mounted() {}
};
</script>

<style lang="scss" scoped>
.my-questions {
  background-color: #f7f7fa;
  min-height: 100vh;
  width: 7.2rem;
  .questions-list {
    padding: 0.288rem;
    .question-box {
      width: 6.624rem;
      height: 2.112rem;
      background-color: #ffffff;
      border-radius: 0.096rem;
      padding: 0.192rem;
      display: flex;
      align-items: center;
      justify-content: space-between;
      margin-bottom: 0.192rem;
      .box-left {
        width: 2.592rem;
        height: 1.728rem;
        background: var(--theme-color);
        position: relative;
        img {
          width: 100%;
          height: 100%;
          display: block;
        }
        .delete_tag{
          position: absolute;
          left: 0;
          top: 0;
        }
      }
      .box-right {
        width: 3.45rem;
        height: 1.728rem;
        .question-name {
          font-size: 0.288rem;
          font-weight: bold;
          color: #313233;
          white-space: nowrap;
          overflow: hidden;
          text-overflow: ellipsis;
        }
        .question-time {
          margin: 0.15rem 0 0.288rem;
          font-size: 0.2496rem;
          color: #c6c7cc;
        }
        .question-progress {
          width: 100%;
          // height: .192rem;
          height: 0.35rem;
        }
        .question-info {
          display: flex;
          justify-content: space-between;
          font-size: 0.2496rem;
        }
      }
    }
  }
}
</style>
